package pos.datos;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import pos.dominio.Horario;

public class JDBCDiarioDAO implements IDiarioDAO{
	
 
	
	public Date obtenerDia() {
		
		Connection conn = ConnectionManager.getInstance().checkOut();
        PreparedStatement stmt = null;
        ResultSet result = null;
        Date dia= new java.sql.Date(0);
        try {

            String sql = "SELECT dia FROM diario";
            stmt = conn.prepareStatement(sql); 
            stmt.executeQuery();
            result = stmt.executeQuery();
            result.next();
            dia= result.getDate("dia");      
           
                  
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            ConnectionManager.getInstance().checkIn(conn);
            try {
                if (result != null)
                    result.close();
                if (stmt != null)
                    stmt.close();
            } catch (SQLException e) {
            }

        }
        return dia;
	}


	
	

	
	
	public void ponerDia(Date dia_actual) {
	
		Connection conn = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		String sql = "UPDATE diario SET dia = ? ";
    try {
        
        stmt = conn.prepareStatement(sql);
        stmt.setDate(1,dia_actual);
        stmt.executeUpdate();

      
    } catch (SQLException e) {
        System.out.println("Message: " + e.getMessage());
        System.out.println("SQLState: " + e.getSQLState());
        System.out.println("ErrorCode: " + e.getErrorCode());
    } finally {
        ConnectionManager.getInstance().checkIn(conn);
        try {
            
            if (stmt != null)
                stmt.close();
        } catch (SQLException e) {
        }
    }
}
	}


